package com.just.dom4j;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

/**
 * 创建一个新的xml文档
 */
public class CreateXML {
    public static void main(String[] args) {
        System.out.println(createDocument().asXML());
    }

    public static Document createDocument() {
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement("root");
        root.addElement("author")
                .addAttribute("name", "James")
                .addAttribute("location", "UK")
                .addText("James strachan");
        root.addElement("author")
                .addAttribute("name", "Bob")
                .addAttribute("location", "US")
                .addText("Bob green");
        return document;
    }
}
